package com.qf.usefull.dict.utils;

import com.qf.usefull.dict.entity.Word;
import com.qf.usefull.dict.service.MyDictionary;

public class DictionaryUtils {

    /**
     * 测试向字典中插入单词的速度
     * @param source
     * @param dictionary
     */
    public static void testAddSpeed(Word[] source, MyDictionary dictionary){

        long start = System.currentTimeMillis();

        for (int i = 0; i < source.length; i++) {
            dictionary.addWord(source[i].getEnglish(),source[i].getChinese());
        }

        long end = System.currentTimeMillis();

        System.out.println("测试字典对象:"+dictionary);
        System.out.println("耗时:"+(end-start)+" ms");
    }


    public static void testFindSpeed(Word[] wordArr, MyDictionary dict) {
        long start = System.currentTimeMillis();
        // 查询所有单词
        for (int i = 0; i < wordArr.length; i++) {
            String english = wordArr[i].getEnglish();
            dict.findWord(english);
        }
        long end = System.currentTimeMillis();
        System.out.println("测试字典对象:"+dict);
        System.out.println("耗时:"+(end-start)+" ms");
    }

}
